#!/bin/sh

if [ "${2}" = "POST-INSTALL" ]; then
	exit 0
fi

# Do not run during build installation
if [ ! -f ${PKG_ROOTDIR}/cf/conf/config.xml ]; then
	exit 0
fi

if ! /usr/bin/grep -q "net.pf.request_maxcount" ${PKG_ROOTDIR}/boot/loader.conf \
    ${PKG_ROOTDIR}/boot/loader.conf.local 2>/dev/null; then
	_value=$(${PKG_ROOTDIR}/usr/local/sbin/read_xml_tag.sh string \
	    system/maximumtableentries)
	if [ -z "${_value}" ]; then
		# Default value is minimumtableentries_bogonsv6 from globals.inc
		_value="400000"
	fi

	if [ -z "${_value}" ]; then
		echo "===> WARN: Impossible to set net.pf.request_maxcount"
	else
		echo "===> Setting net.pf.request_maxcount=${_value}"
		echo "net.pf.request_maxcount=${_value}" >> ${PKG_ROOTDIR}/boot/loader.conf
	fi
fi

if [ -f ${PKG_ROOTDIR}/usr/local/share/%%PRODUCT_NAME%%/fix_for_SA-19-10.ufs ]; then
	exit 0
fi

echo "===> Flagging this system to apply fix for FreeBSD-SA-19:10.ufs"
touch ${PKG_ROOTDIR}/.fix_for_SA-19-10.ufs
